<script type="text/javascript">
function change(value)
{
	var div1=document.getElementById('div1');
	var div2=document.getElementById('div2');
	var div3=document.getElementById('div3');
	if(value==''||value==null)
	{
		alert('请选择合同类型');
	}
	if(value=="1")
	{
		document.getElementById('div1').style.display='block';
		document.getElementById('div2').style.display='none';
		document.getElementById('div3').style.display='none';
	}
	if(value=="2")
	{
		document.getElementById('div2').style.display='block';
		document.getElementById('div1').style.display='none';
		document.getElementById('div3').style.display='none';
	}
	if(value=="3")
	{
		document.getElementById('div3').style.display='block';
		document.getElementById('div2').style.display='none';
		document.getElementById('div1').style.display='none';
	}
}

function setValue()
{
	var types=document.getElementsByName("type");
	for(var i=0;i<types.length;i++)
	{
		if(types[i].checked)
		{
			var index=types[i].value;
			var firstnames=document.getElementById('firstname'+index);
			var secondnames=document.getElementById('secondname'+index);
			
			var firstname=document.getElementById('firstname');
			var secondname=document.getElementById('secondname');
			firstname.value=firstnames.value;
			secondname.value=secondnames.value;
			
		}
	}
	
	/* var projectid1=document.getElementById('projectid1');
	var businesstype1=document.getElementById('businesstype');
	var projectid=document.getElementById('projectid');
	//var businesstype=document.getElementById('businesstype');
	
	if(businesstype1.value=='投标合同')
	{
		projectid1.value=0;
		
	}
	projectid.value=projectid1.value; */
	//alert(projectid.value);
	//businesstype.value=businesstype1.value;
	
}

//中文逗号替换成英文逗号
function ReplaceDot()
{
     var Obj=document.getElementById('goodname');
     var oldValue=Obj.value;
     while(oldValue.indexOf("，")!=-1)//寻找每一个中文逗号，并替换
     {
         Obj.value=oldValue.replace("，",",");
         oldValue=Obj.value;
     }
}

</script>
<div class="pageContent">
	<form method="post" action="__URL__/remind/insert/true/navTabId/remind/callbackType/closeCurrent"  enctype="multipart/form-data"  class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone)" >
		<input type="hidden" name="userid" value="<?php echo $_SESSION[C('USER_AUTH_KEY')] ?>"/>
		<input type="hidden" name="firstname" id="firstname">
		<input type="hidden" name="secondname" id="secondname"> 
		<input type="hidden" name="pid" value="{$id}">
		<input type="hidden" name="contractdate" value="<?php echo date('YmdHis')?>">
		<input type="hidden" name="creator" value="<?php echo $_SESSION['username'] ?>">
		<div class="pageFormContent" layoutH="58">
		 <div class="unit">
				<label style="margin-right: -40px;">选择合同类型：</label>
				<input type="radio" name="type"  value="1" checked onclick="change(this.value);"/>客户合同
				<input type="radio" name="type" value="2"  onclick="change(this.value);"/>供应商合同
				<input type="radio" name="type"  value="3"  onclick="change(this.value);"/>承运商合同
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span><font color="red">请先选择合同类型</font></span>
		 </div>
		 <div id="div1" style="display:block">
		    <p class="unit">
				<label style="margin-right: -10px;">甲方：</label>
				<select name="firstname1" id="firstname1" class="combox">
					<option value="" selected>请选择</option>
					<volist id="subs" name="subcompany">
					<option value="{$subs.subname}" >{$subs.subname}</option>
					</volist>
				</select>
			</p>
			<p class="unit" >
				<label>乙方：</label>
				<input type="hidden" name="secondid1"/>
				<input type="text" id="secondname1"  name="secondname1" value="{$business['companyname']}"><a class="btnLook" href="__URL__/getcustomer"  lookupGroup="" >查找带回</a>
			</p>
			</div>
			<div id="div2" style="display:none">
			    <p class="unit">
					<label>甲方：</label>
					<input type="text"  name="secondname2" id="secondname2" value="{$business['companyname']}">
					<input type="hidden" name="secondname2"/>
					<a class="btnLook" href="__URL__/getprovider"  lookupGroup="" >查找带回</a>
				</p>
				<p class="unit">
					<label style="margin-right: -10px;">乙方：</label>
					<select name="firstname2" id="firstname2" class="combox">
						<option value="" selected>请选择</option>
					<volist id="subs" name="subcompany"><option value="{$subs.subname}" >
					{$subs.subname}</option></volist>
					</select>
				</p>
			</div>
			<div id="div3" style="display:none">
			    <p class="unit">
					<label style="margin-right: -10px;">甲方：</label>
					<select id="firstname3" name="firstname3" class="combox">
						<option value="" selected>请选择</option>
					<volist id="subs" name="subcompany"><option value="{$subs.subname}" >{$subs.subname}</option></volist>
					</select>
				</p>
				<p class="unit">
					<label>乙方：</label>
					<input type="hidden" name="secondid3"/>
					<input type="text" name="secondname3" id="secondname3" value="{$business['companyname']}"><a class="btnLook" href="__URL__/getcarrier"  lookupGroup="" >查找带回</a>
				</p>
			</div>
			<div class="unit">
				<label>乙方人：</label>
				<input type="text"   name="seconder" value="{$business['linkname']}">
			</div>
			<div class="unit">
				<label>乙方电话：</label>
				<input type="text"  name="secondphone" value="{$business['phone']}">
			</div>
			<!--  
			<div class="unit">
						<label>请选择合同附件：</label> <input type="file" name="fileids" style="height: 21px;" />
					</div>-->
			<div class="unit">
				<label>合同标题：</label>
				<input type="text"   name="subject">
			</div>
			<div class="unit">
				<label>合同编号：</label>
				<input type="text"  name="contractno"   value="<?php echo date('YmdHis')?>">
			</div>
			<!--
			<div class="unit">
				<label>商品名称：</label>
				<input type="hidden"   name="goodid">
				<input type="text"   id="goodname" onKeyUp="ReplaceDot();"
				 name="goodname" value="{$business['productname']}">
				<a class="btnLook" href="__URL__/getgoods" lookupGroup="">查找带回</a><span><font color="red">输入多个商品名称，请用英文逗号隔开</font></span>
			</div>
			  
			<div class="unit">
				<label>商品类型：</label>
				<input type="text"   name="goodtype">
			</div>
			
			<div class="unit">
				<label>金额：</label>
				<input type="text" class="number" id="totalprice" name="totalprice" onblur="setVal();">
			</div>
			<div class="unit">
				<label>单价：</label>
				<input type="text" class="number" id="price" name="price" onblur="setVal();">
			</div>
			<script type="text/javascript">
				function setVal() {
					//var quality=document.getElementById('quality').value;
					var totalprice = document.getElementById('totalprice');
					var price = document.getElementById('price');
					var quality = document.getElementById('quality');
					//totalprice.value=quality*price;
					if(totalprice.value!=null&&totalprice.value!=""&&price.value!=null&&price.value!="")
					{
					  quality.value = totalprice.value / price.value;
					}
					else if(quality.value!=null&&quality.value!=""&&price.value!=null&&price.value!="")
					{
						totalprice.value=quality.value*price.value;
						
					}
				}
				
				function hideText()
				{
					document.getElementById('totalprice').value="";
				}
			</script>
			<div class="unit">
				<label>购买数量：</label>
				<input type="text" class="number" id="quality" name="quality" onblur="setVal();" onkeydown="hideText();" value="{$business['quantity']}">
			</div>-->
			<div class="unit">
				<label>提货周期：</label>
                <input type="text" name="deadline" class="date"><a class="inputDateButton" href="javascript:;" style="">选择</a>
				<label>至：</label>
				<input type="text" name="deadlined" class="date"><a class="inputDateButton" href="javascript:;" style="">选择</a>
			</div>
			<div class="unit">
				<label>主要条款：</label>
				<textarea rows="3" cols="55" style="width: 360px;" name="mainitem"></textarea>
			</div>
			<div class="unit">
				<label>售后条款：</label>
				<textarea rows="3" cols="55" style="width: 360px;" name="salesafteritem"></textarea>
			</div>
			<div class="unit">
				<label>生效日期：</label>
				<input type="text" name="validdae" class="date" /><a class="inputDateButton" href="javascript:;" style="">选择</a>
			</div>
			<div class="unit">
				<label>有效截止日期：</label>
				<input type="text" name="expiredate" class="date" ><a class="inputDateButton" href="javascript:;" style="">选择</a>
			</div>
			<div class="unit">
				<label>签约人：</label>
				<input type="text" name="signupuser" >
			</div>
			<div class="unit">
				<label>签约时间：</label>
				<input type="text" name="signuptime" class="date"/><a class="inputDateButton" href="javascript:;">选择</a>
			</div>
			<div class="unit">
				<label style="margin-right:-10px">合同来源：</label>
				<input type="hidden" id="projectid" name="projectid" value="{$id}"/>
				<select   id="businesstype" name="businesstype" class="combox">
						<option value="投标合同">投标合同</option>
						<option value="购进合同" <eq name="business['type']" value="购进合同">selected</eq>>购进合同</option>
						<option value="销售合同"  <eq name="business['type']" value="销售合同">selected</eq>>销售合同</option>
					</select>
			   <!--  <input type="text" name="businesstype" value="{$business['type']}" readonly/>--><a  href="__URL__/lookup/id/{$id}"  style="float:left;margin-left:10px" rel="look" height="250" mask="true" target="dialog"><font color="red">查看</font></a> 	
			</div>
			<div class="unit">
				<label>收货地址：</label>
				<input type="text" name="consignaddress" style="width: 360px;">
			</div>
			<div class="unit">
				<label>收货人：</label>
				<input type="text" name="consignee">
			</div>
			<div class="unit">
				<label>结算方式：</label>
				<input type="text" name="clearform">
			</div>
			
			<table class="table" width="100%">
			           <thead>
							<tr>
							 <th>商品名称</th>
			                 <th>购买数量</th>
			                 <th>产品单价/吨</th>
			                 <th>金额</th>
			                 <!--  
		                     <th type="del" width="60">操作</th>-->
		                    </tr>
						</thead>
					<tbody>
						<volist id="con" name="bg">
						<tr target="sid_node" rel="{$con['id']}">
						<td>{$con['goodname']}</td>
						<td>{$con['quality']}</td>
						<td>{$con['price']}</td>
						<td>{$con['totalprice']}</td>
						<!--<td><a href="__URL__/goodsedit/id/{$con['id']}" target="dialog" rel="goodedit" mask="true" title="修改业务"  width="540" height="320">修改</a> | <a href="#">删除</a></td>-->
						</tr>
						</volist>
					</tbody>
			</table>		
		</div>
		
		<div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit" onclick="setValue();">保存</button></div></div></li>
				<li><div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div></li>
			</ul>
		</div>
	</form>

</div>

